define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'house/housepark/index' + location.search,
                    add_url: 'house/housepark/add',
                    //edit_url: 'house/housepark/edit',
                    del_url: 'house/housepark/del',
                    multi_url: 'house/housepark/multi',
                    import_url: 'house/housepark/import',
                    table: 'house_park',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'park_id',
                sortName: 'park_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'park_id', title: __('Park_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'house_id', title: __('House_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'brand', title: __('Brand'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'lat', title: __('Lat'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'lng', title: __('Lng'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'property_company_name', title: __('Property_company_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'property_company_mobile', title: __('Property_company_mobile'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'contact_name', title: __('Contact_name'), operate: 'LIKE'},
                        {field: 'contact_mobile', title: __('Contact_mobile'), operate: 'LIKE'},
                        {field: 'area', title: __('Area'), operate: 'LIKE'},
                        {field: 'floor_num', title: __('Floor_num')},
                        {field: 'room_num', title: __('Room_num')},
                        {field: 'parking_spot_num', title: __('Parking_spot_num')},
                        {field: 'type', title: __('Type'),  formatter: Table.api.formatter.status, searchList: { 1: __('公寓'), 2: __('楼房'), 3: __('别墅'), 4: __('其他')}},
                        {field: 'house_type', title: __('House_type'), formatter: Table.api.formatter.normal, searchList: { 1: __('一室'), 2: __('二室'), 3: __('三室'), 4: __('多室')}},
                        // {field: 'complement_id', title: __('Complement_id'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'scenic_id', title: __('Scenic_id'), operate: 'LIKE'},
                        // {field: 'manage_id', title: __('Manage_id'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {0: __('待审核'), 1: __('审核通过'), 2: __('审核拒绝')}},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'change',
                                    text: __('已完善'),
                                    confirm:'确认园区信息已完善吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'house/housepark/change',
                                    visible:function(row){
                                        if(row.can_change == 1){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'recommend',
                                    text: __('推荐'),
                                    confirm:'确认推荐吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'house/housepark/recommend',
                                    visible:function(row){
                                        if(row.is_recommend == 0){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'cancel_recommend',
                                    text: __('取消推荐'),
                                    confirm:'确认取消推荐吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'house/housepark/cancelrecommend',
                                    visible:function(row){
                                        if(row.is_recommend == 1){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'settop',
                                    text: __('置顶'),
                                    confirm:'确认置顶吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'house/housepark/settop',
                                    visible:function(row){
                                        if(row.is_top == 0){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'cancel_top',
                                    text: __('取消推荐'),
                                    confirm:'确认取消置顶吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'house/housepark/canceltop',
                                    visible:function(row){
                                        if(row.is_top == 1){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'detail',
                                    text: __('详情'),
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'house/housepark/detail',
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'house/housepark/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'house/housepark/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'house/housepark/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
